package spring.cloud.study.entity.base;

import java.text.MessageFormat;

import lombok.Getter;
import lombok.Setter;

/**
 * 返回状态信息枚举类
 * @author wh
 *
 */
public enum RespCodeEnum {
	
    SUCCESS("0000", "成功"),
    FAIL("9999", "失败"),
    EXCEPTION("9998", "服务器内部异常：{0}"),

    NULL_ERROR("0011", "{0}不能为空"),
    NOT_NULL_ERROR("0012", "{0}必须为空"),
    NOT_EXIST_ERROR("0013", "{0}数据库中不存在"),
    EXIST_ERROR("0014", "{0}数据库中已存在"),
    PARAM_TYPE_ERROR("0015", "{0}类型错误"),
    PARAM_FORMAT_ERROR("0016", "{0}格式错误"),
    ;
	
	@Getter
	@Setter
    private String code;
	@Getter
	@Setter
    private String desc;
    
	RespCodeEnum(String code, String desc) {
		this.code = code;
		this.desc = desc;
	}
    
    
    public String getName(){
        return this.name();
    }

    /** 将入参fieldNames与this.desc组合成错误信息
     *  {fieldName}不能为空
     * @param fieldNames
     * @return
     */
    public String parseError(Object... fieldNames) {
        //ResponseModel errorMessage = new ResponseModel();
        String newDesc = MessageFormat.format(this.desc, fieldNames);

       // errorMessage.setRepCode(this.code);
       // errorMessage.setRepMsg(newDesc);
        return newDesc;
    }
    
    public static void main(String[] args) {
    	System.out.println(ResponseModel.errorMsg(RespCodeEnum.NULL_ERROR.parseError("用户ID")).toJsonString());
	}

}
